//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_mhqcheckneartarget.sqf"
#include "x_setup.sqf"

private ["_vec", "_ti"];
_vec = vehicle player;
while {GVAR(player_in_vec)} do {
	if (fuel _vec != 0 && {player == driver _vec} && {!(_vec in list GVAR(base_trigger))}) then {
		_ti = __XJIPGetVar(GVAR(current_target_index));
		if (_ti != -1) then {
			_current_target_pos = (GVAR(target_names) select _ti) select 0;
			if (_vec distance _current_target_pos <= GVAR(MHQDisableNearMT)) then {
				_vec setVariable [QGVAR(vecfuelmhq), fuel _vec, true];
				_vec setFuel 0;
				[QGVAR(mqhtn), GV(_vec,GVAR(vec_name))] call FUNC(NetCallEventToClients);
				[format [(localize "STR_DOM_MISSIONSTRING_520"), GVAR(MHQDisableNearMT), GV(_vec,GVAR(vec_name))], "HQ"] call FUNC(HintChatMsg);
			};
		};
	};
	sleep 0.531;
};
GVAR(playerInMHQ) = false;
